<template>
    <div>
        <el-tabs type="border-card">
            <el-tab-pane label="下发任务">
                <br />
                <el-table :data="taskData" style="width: 100%" border>
                    <el-table-column prop="number" label="序号" width="50"> </el-table-column>
                    <el-table-column prop="name" label="任务标题"> </el-table-column>
                    <el-table-column prop="acceptDeptId" label="接受部门" width="150"> </el-table-column>
                    <el-table-column prop="type" label="任务属性" width="100">
                        <template slot-scope="scope">
                            <div v-if="scope.row.type == 0">A</div>
                            <div v-else-if="scope.row.type == 1">B</div>
                            <div v-else-if="scope.row.type == 2">C</div>
                            <div v-else></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="level" label="分配次级" width="100">
                        <template slot-scope="scope">
                            <div v-if="scope.row.level == 0">一级</div>
                            <div v-else-if="scope.row.level == 1">二级</div>
                            <div v-else-if="scope.row.level == 2">三级</div>
                            <div v-else></div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="isAssess" label="学校年度专项考核" width="130">
                        <template slot-scope="scope">
                            <div v-if="scope.row.isAssess == 0">否</div>
                            <div v-else-if="scope.row.isAssess == 1">是</div>
                            <div v-else></div>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
        </el-tabs>

    </div>
</template>

<script>
import personApi from '../../../../api/person';
import departmentApi from '../../../../api/department';
import yearTargetApi from '../../../../api/yearTagetApi';
import workOfYearTargetApi from '../../../../api/workOfYearTargetApi';

export default {
    props: {
        // 年份名字
        targetYear: String,
        // 年份id
        targetId: String,
        // 筛选部门名称
        departmentName: String
    },
    data() {
        return {
            departmentOptions: [],
            teacherOptions: [],
            taskData: [],
            addDialogVisible: false,
            collegeYearTestoptions: [
                {
                    value: -1,
                    label: '--'
                },
                {
                    value: 1,
                    label: '是'
                },
                {
                    value: 0,
                    label: '否'
                }
            ],
            addTaskInfoForm: {},
            eidtTaskDialogVisible: false,
            editTaskInfoForm: {},

            taskType: 0,

            is_collegeYearTest: '',

            yearTargetOptions: [],
            data: [],
            defaultProps: {
                children: 'children',
                label: 'label'
            },
            allocDeptId: '',
            editTemp: ''
        };
    },
    methods: {
        // 获取所有老师
        async getTeachers() {
            await personApi.getAllTeacher().then((res) => {
                for (let i = 0; i < res.data.length; ++i) {
                    this.teacherOptions[i] = {
                        value: res.data[i].id,
                        label: res.data[i].name
                    };
                }
                // 强制刷新 解决有数据不渲染的问题
                this.$forceUpdate();
            });
        },
        async getDepartment() {
            await departmentApi.getAllDepart().then((res) => {
                for (let i = 0; i < res.data.length; ++i) {
                    this.departmentOptions[i] = {
                        value: res.data[i].id,
                        label: res.data[i].name
                    };
                }
                // 强制刷新 解决有数据不渲染的问题
                this.$forceUpdate();
            });
        },
        // 查b类2级
        async searchWorkOfTargetYear() {
            await workOfYearTargetApi.getWorkOfYearTarget(this.targetId, 1).then((res) => {
                this.taskData = res.data;
                let temp = this.taskData;
                let tempTaskData = []
                for(let i=0;i<this.taskData.length;++i){
                    if(this.taskData[i].level == 1&& this.taskData[i].allocDeptId == this.departmentName){
                        tempTaskData.push(this.taskData[i]);
                    }
                }
                this.taskData = tempTaskData
            });
        },
        //
        async getDepartmentName(id) {
            await departmentApi.getDepartmentById(id).then((res) => {
                this.addTaskInfoForm.allocDeptId = res.data.name;
                this.allocDeptId = res.data.name;
            });
        },
    },
    created() {
        this.getDepartment();
        this.getTeachers();
        this.getDepartmentName(this.$store.state.user.deptId);
    },
    watch: {
        departmentName(){
            this.searchWorkOfTargetYear()
        }
    }
};
</script>

<style scoped>
.el-tree-style {
    padding: 0px 40px;
}
.el-tree-node__label {
    color: #606266;
}
.el-tag {
    float: right;
}
.title {
    border: 1px #bcbcbc;
    width: 50%;
    margin: 0 auto;
}
.card {
    border-radius: 15px;
    width: 50%;
    margin: 0 auto;
}
.el-menu-item.is-active {
    color: #409eff;
}
.menu-buttom {
    padding-bottom: 20px;
}
</style>


